<template>
  <div
    class="brand-detail"
    v-title
    :data-title="$t('router.labelsNationalTitle')"
  >
    <Breadcrumb></Breadcrumb>
    <header class="head-box" v-loading="fullscreenLoading">
      <div class="image">
        <el-image :src="detailData.minImg" fit="contain">
          <div slot="placeholder" class="image-slot flex-center flex-column">
            <i class="iconfont el-icon-loading"></i>
            <p>
              {{ $t("public.loading") }}
              <span class="dot">...</span>
            </p>
          </div>
          <div slot="error" class="image-slot flex-center">
            <img src="@/assets/images/defaultCover.png" />
          </div>
        </el-image>
      </div>
      <div class="head-info">
        <h2 class="ellipsis-two">{{ detailData.displayName }}</h2>
        <div class="head-info-content">{{ detailData.blurb }}</div>
      </div>
    </header>
    <div
      class="list"
      v-infinite-scroll="load"
      infinite-scroll-disabled="isPage"
      infinite-scroll-delay="120"
      infinite-scroll-distance="10"
      infinite-scroll-immediate="false"
    >
      <album-list
        :listData="list"
        :loading="loading"
        v-loading="fullscreenLoading"
      ></album-list>
    </div>
    <nice-empty
      v-show="list.length == 0 && fullscreenLoading == false"
      :emptyText="$t('public.noData')"
    ></nice-empty>
    <div class="page-wrap" v-show="isPage">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.pageNum"
        :page-size="params.pageSize"
        background
        hide-on-single-page
        layout="total, prev, pager, next, jumper"
        :total="total"
        :small="isMobile"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import Breadcrumb from "@/components/common/Breadcrumb/Index";
import albumList from "@/components/common/albumList/Index";
export default {
  data() {
    return {
      detailData: {}, //详情页数据
      list: [], //列表数据
      // 是否显示加载动画
      loading: false,
      // 是否还有数据
      loadStatus: true,
      // 请求参数
      params: {
        // 返回数量
        pageSize: 30,
        // 当前页数
        pageNum: 1,
      },
      //数据载入动画
      fullscreenLoading: true,
      //是否显示分页
      isPage: false,
      total: 0, //总条数
    };
  },
  components: {
    Breadcrumb,
    albumList,
  },
  computed: {
    isMobile() {
      return this.$store.getters.isMobile;
    },
    isIE() {
      return this.$store.getters.isIE;
    },
  },
  watch: {},
  created() {},
  mounted() {
    if (this.isIE) {
      this.params.pageSize = 50;
    }
    this.getLabelInfo();
    this.getLabelAlbum();
  },
  methods: {
    //分页 每页条数
    handleSizeChange(val) {
      this.params.pageSize = val;
      this.getLabelAlbum();
    },
    //当前页
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.list = [];
      this.getLabelAlbum();
    },
    // 获取厂牌详情
    async getLabelInfo() {
      this.fullscreenLoading = true;
      try {
        let params = {
          catlabelId: this.$route.params.id,
        };
        let res = await this.$api.national.getLabelInfo(params);
        if (res.code === 1000000) {
          this.detailData = res.source ? res.source : {};
          this.fullscreenLoading = false;
        }
      } catch (e) {
        console.log(e);
      }
    },
    //获取厂牌下专辑列表
    async getLabelAlbum() {
      this.fullscreenLoading = true;
      try {
        let params = {
          catlabelId: this.$route.params.id,
        };
        this.loadStatus = false;
        let res = await this.$api.national.getLabelAlbum({
          ...this.params,
          ...params,
        });
        if (res.code === 1000000) {
          this.list = res.source
            ? this.utils.processingData(this.list, res.source)
            : [];
          this.total = res.total;
          this.fullscreenLoading = false;
          if (res.size < 50 && res.size < res.total) {
            this.loading = true;
            this.loadStatus = true;
            this.isPage = false;
          } else {
            this.loading = false;
            this.isPage = true;
          }
        }
      } catch (e) {
        console.log(e);
      }
    },
    // 加载更多
    load() {
      this.params.pageSize += 20;
      this.getLabelAlbum();
    },
  },
};
</script>

<style lang="scss" scoped>
.brand-detail {
  .head-box {
    width: 100%;
    display: flex;
    margin: 30px 0 4px 0;
    border-bottom: 1px solid #eeeeee;
    padding-bottom: 24px;
    margin-bottom: 20px;
    .el-image {
      width: 224px;
      height: 224px;
      line-height: 224px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .head-info {
      width: calc(100% - 288px);
      margin: 0 32px;
      overflow: hidden;
      h2 {
        height: 56px;
        line-height: 28px;
        font-weight: 500;
        font-size: 20px;
        margin-bottom: 32px;
      }
      .head-info-content {
        width: 100%;
        max-height: 126px;
        line-height: 25px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 4;
      }
    }
  }
}
</style>
